package org.thread.test02.homework2;/*
 *@Author: gjh
 *Date: 2025/3/715:23
 *Describe:
 */

import java.io.*;

public class CopyThread extends Thread{
    @Override
    public void run() {
        try {
            // 创建文件输入流
            FileInputStream inputStream = new FileInputStream("C:\\Users\\86130\\Desktop\\1.txt");
            // 创建文件输出流
            FileOutputStream outputStream = new FileOutputStream("C:\\Users\\86130\\Desktop\\2.txt");
            // 获取源文件
            File file = new File("C:\\Users\\86130\\Desktop\\1.txt");
            // 获取源文件大小
            Test.test.count = file.length();
            // 传输的字节数
            Test.test.doneByte = 0;
            // 准备byte数组
            byte[] bytes = new byte[1024];
            // 一边读
            int readCount = 0;
            while ((readCount=inputStream.read(bytes))!=-1){
                outputStream.write(bytes,0,readCount);
                Test.test.doneByte += readCount;
                Thread.sleep(10);
            }
            System.out.println("拷贝完成！");
            outputStream.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

    }
}
